package ua.com.infinite.mobile.activities;

import ua.com.infinite.mobile.R;
import ua.com.infinite.mobile.R.id;
import ua.com.infinite.mobile.plains.NewsItem;
import ua.com.infinite.mobile.utils.imageloader.ImageLoader;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class ActivityNewsDetailed extends Activity {

	private ImageLoader imageLoader;
	private NewsItem item;

	private ImageView poster_icon;
	private TextView poster_name;
	private TextView post_title;
	private TextView post_text;
	private TextView post_date;
	private ImageView post_img;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_news_detailed);
		poster_icon = (ImageView) findViewById(R.id.poster_icon);
		poster_name = (TextView) findViewById(R.id.poster_name);
		post_title = (TextView) findViewById(R.id.post_title);
		post_text = (TextView) findViewById(R.id.post_text);
		post_date = (TextView) findViewById(R.id.post_date);
		post_img = (ImageView) findViewById(R.id.post_img);

		Bundle b = getIntent().getExtras();
		if (b != null || savedInstanceState != null) {
			if (b != null) {
				item = b.getParcelable("news_item");
			} else {
				item = savedInstanceState.getParcelable("news_item");
			}
		}
		if (item == null) {
			finish();
		}
		imageLoader = new ImageLoader(getApplicationContext());
		imageLoader.DisplayImage(item.poster_icon, poster_icon);
		if (item.post_imgs.length != 0)
			imageLoader.DisplayImage(item.post_imgs[0], post_img);
		poster_name.setText(item.poster_name);
		post_title.setText(item.post_title);
		post_text.setText(item.post_text);
		post_date.setText(item.post_date);

	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		if (item != null)
			outState.putParcelable("news_item", item);
	}

}
